package com.zlsy.thread.synchronizedlearing;

/**
 * @author zhouliang
 * @date 2020/03/02
 **/
public class SynchronizeClassStaticLock implements Runnable {

    static SynchronizeClassStaticLock instance1 = new SynchronizeClassStaticLock();
    static SynchronizeClassStaticLock instance2 = new SynchronizeClassStaticLock();

    @Override
    public void run() {
        register();
    }

    private static synchronized void register() {
        System.out.println("我是类锁的第一种形式：static形式，我叫：" + Thread.currentThread().getName());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "运行结束");
    }

    public static void main(String[] args) {
        Thread thread = new Thread(instance1);
        Thread thread1 = new Thread(instance2);
        thread.start();
        thread1.start();

        while (thread.isAlive() || thread1.isAlive()) {
        }

        System.err.println("game over！");
    }
}
